import React from 'react';
import { Col, Empty, Form, Row } from 'antd';
import { createDictionary } from '@/dictionary';
import FormContainer from './FormContainer';

// 劳动合同年限单位
const [, getContractDurationUnitText] = createDictionary('CONTRACT_DURATION_UNIT_DICT');
const [, getTryDurationUnitText] = createDictionary('TRY_DURATION_UNIT_DICT');
const [, getServiceStatusName] = createDictionary('SERVICE_STATUS_DICT');

/**
 * 员工档案 - 在职信息 - 员工状态
 */
const EmployeeStatusSection = ({ formData }) => {
    const renderDuration = () => {
        if (!formData.contractDuration) {
            return '--';
        }
        if (formData.contractDuration === -1) {
            return '无固定期限';
        }
        return (
            <span>
                {formData.contractDuration}
                {getContractDurationUnitText(formData.contractDurationUnit && Number(formData.contractDurationUnit))}
            </span>
        );
    };

    // render
    return (
        <FormContainer title="员工状态" hasEditAuth={false}>
            {() =>
                formData ? (
                    <>
                        <Row gutter={24}>
                            <Col span={12}>
                                <Form.Item label="状态">
                                    <span>{getServiceStatusName(formData.serviceStatus)}</span>
                                </Form.Item>
                            </Col>
                            <Col span={12}>
                                <Form.Item label="工作性质">
                                    <span>{formData.workNatureName || '--'}</span>
                                </Form.Item>
                            </Col>
                        </Row>
                        <Row gutter={24}>
                            <Col span={12}>
                                <Form.Item label="入职日期">
                                    <span>{formData.timeOfEntry || '--'}</span>
                                </Form.Item>
                            </Col>
                            <Col span={12}>
                                <Form.Item label="劳动合同年限">{renderDuration()}</Form.Item>
                            </Col>
                        </Row>
                        <Row gutter={24}>
                            <Col span={12}>
                                <Form.Item label="试用期">
                                    {formData.tryDuration ? (
                                        <span>
                                            {formData.tryDuration}
                                            {getTryDurationUnitText(
                                                formData.tryDurationUnit && Number(formData.tryDurationUnit)
                                            )}
                                        </span>
                                    ) : (
                                        '--'
                                    )}
                                </Form.Item>
                            </Col>
                            <Col span={12}>
                                <Form.Item label="转正日期">
                                    <span>{formData.correctionTime || '--'}</span>
                                </Form.Item>
                            </Col>
                        </Row>
                        <Row gutter={24}>
                            <Col span={12}>
                                <Form.Item label="司龄">
                                    <span>{formData.entryDuration || '--'}</span>
                                </Form.Item>
                            </Col>
                        </Row>
                    </>
                ) : (
                    <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
                )
            }
        </FormContainer>
    );
};

export default EmployeeStatusSection;
